package com.cbw.firegame.product.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cbw.common.vo.GameEntity;
import com.cbw.common.vo.GameInfoEntity;
import com.cbw.firegame.product.service.GameInfoService;
import com.cbw.firegame.product.service.GameService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
public class SchedureTask {
  @Autowired
    GameService gameService;
    @Autowired
    GameInfoService gameInfoService;
    @Scheduled(cron = "0 0 0 * * ?")
    public void deleteUnGame(){
        List<GameEntity> unGames = gameService.list(new QueryWrapper<GameEntity>().eq("status", 0));
        if (unGames!=null&&unGames.size()>0){
            unGames.forEach(item->{
                GameInfoEntity gameinfo = gameInfoService.getOne(new QueryWrapper<GameInfoEntity>().eq("game_detail_id", item.getGameDetailId()));
                if (gameinfo!=null){
                    gameInfoService.removeById(gameinfo);
                }
                gameService.removeById(item);
            });
        }
        log.info("执行了定时任务");
    }



}
